<?php
header("Content-Type: text/html; charset=utf-8"); 

require_once("config.inc.php");
require_once(COMM_PATH."book.php");
require_once(COMM_PATH."tools.php");
$book = new Book();


//	$BOOKID = $_GET['BID'];
//	$CH = $_GET['CH'];
//	$CHN = $_GET['CHN'];
$The_book = $book->getBook($BOOKID);
if($The_book){
	$categroy = $book->getInfo($The_book[0]['category'], $book->_CATEGORY);
	$CP = $The_book[0]['bookName'];
}else{
	require('404.php');
    @header('HTTP/1.1 404 Not Found');
    @header('Status: 404 Not Found');
    exit;
}

 
$desc = ",".$categroy[0]['cate_name'].",".$The_book[0]["bookName"];
?>
<?php include_once 'top_html.php';?>

<div class="b_lofter bgWhite">
	<div class="breadcrumb">
		您的位置：<a href="/"  title="木篱笆书站">首页</a>&nbsp;/&nbsp;<a href="/CP/<?php echo $The_book[0]['category'];?>/1"><?php echo $categroy[0]['cate_name'];?></a>&nbsp;/&nbsp;<a href="/READLIST/BID/<?php echo $BOOKID;?>"><?php echo $The_book[0]["bookName"];?></a>&nbsp;/&nbsp;正文
	</div>
	<div class="brline">
	</div>
	<div class="book_list book_read">
    	 <?php 
    	 	$filepath = INCLUDE_PATH.$The_book[0]["path"]."/".$CH.".txt";
			$content = "";
			if (file_exists($filepath)){
				$content = file_get_contents($filepath);
			}else {
				echo "<script type=\"text/javascript\">window.location.href=\"404.php\";</script>";
				exit;
			}
			$array = explode("\r\n", $content);
			for($i=0; $i<count($array); $i++)
			{
				if (!strpos($array[$i],"好读书柜")){
					echo $array[$i]."<br/>&nbsp;&nbsp;&nbsp;&nbsp;";
				}
			    
			}
			?>
    </div>
</div>


<?php include_once 'footer.php';?>
<?php 
/**
 * 点击率计算
 */
$cIp = get_real_ip();
$cNum = $book->getCNUMbyBookId($BOOKID);
if($cNum){
	$clickNum = $cNum[0];//获取表记录
	//$updateCNum['BID'] = $clickNum['BID'];
	$updateCNum['PV_NUM'] = intval($clickNum['PV_NUM'])+1;
	$cIPNUM = $book->getIPNUMbyBookId($BOOKID);
	if($cIPNUM){
		$flag = false;
		foreach ($cIPNUM as $key => $value) {
			if ($cIp == $value['IP_ADDR']){
				$flag = true;
				break;
			}
		}
		if (!$flag){
			$updateCNum['IP_NUM'] = intval($clickNum['IP_NUM'])+1;
			//插入数据
			$ipData['BOOK_ID']= $BOOKID;
			$ipData['IP_ADDR']= $cIp;
			$book->insertData($book->_IPNUM, $ipData);
		}
	}else{
		$updateCNum['IP_NUM'] = intval($clickNum['IP_NUM'])+1;
		//插入数据
		$ipData['BOOK_ID']= $BOOKID;
		$ipData['IP_ADDR']= $cIp;
		$book->insertData($book->_IPNUM, $ipData);
	}
	//更新点击量表数据
	$book->updateData($book->_CNUM, $clickNum['BID'], $updateCNum);
}else{//没有记录 第一次保存
	$cData['BOOK_ID'] = $BOOKID;
	$cData['PV_NUM'] = 1;
	$cData['IP_NUM'] = 1;
	$book->insertData($book->_CNUM, $cData);
	$ipData['BOOK_ID']= $BOOKID;
	$ipData['IP_ADDR']= $cIp;
	$book->insertData($book->_IPNUM, $ipData);
}

?>
<div style="height:32px;">&nbsp;</div>
<div class="readTool">
	<input type="button" class="button1" name="list" id="list" value="返回书目" onclick="javascript:window.location.href='/READLIST/BID/<?php echo $BOOKID;?>';" />
	<input type="button"  class="button1" name="up" id="up" value="上一章" onclick="javascript:godownhtml(<?php echo $BOOKID;?>,<?php echo $CHN;?>,<?php echo ($CH-1);?>);" <?php if ($CH==1){?> disabled="disabled" <?php }?>/>
	&nbsp;&nbsp;
	<select name="fsize" id="fsize">
		 
	</select>
	&nbsp;&nbsp;
	<span class="colorSet FFFFFF nowColor">&nbsp;</span>
	<span class="colorSet EEEBC4">&nbsp;</span>
	<span class="colorSet E3EEC4">&nbsp;</span>
	<span class="colorSet D9E8FB">&nbsp;</span>
	<span class="colorSet F1DAB6">&nbsp;</span>
	&nbsp;&nbsp;
	<input type="button" class="button1"  name="down" id="down" value="下一章" onclick="javascript:godownhtml(<?php echo $BOOKID;?>,<?php echo $CHN;?>,<?php echo ($CH+1);?>);" <?php if ($CH==$CHN){?>disabled="disabled" <?php }?>/>
</div>
<script src="<?php echo ROOT_URL?>/resources/js/jquerys/lib/jquery.cookie.js" type="text/javascript"></script><!--cookie-->
<script type="text/javascript" src="<?php echo ROOT_URL?>/resources/js/read.js" ></script>